﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StudSystem
{
    public class Student : ICloneable, IComparable<Student>
    {
        private string firstName;
        private string middleName;
        private string lastName;
        private int socialNumber;
        private string adress;
        private int mobilePhone;
        private string email;
        private string course;
        private Specialty specialty;
        private University university;
        private Faculty faculty;

        public string FirstName
        {
            get { return this.firstName; }
        }
        public string MiddleName
        {
            get { return this.middleName; }
        }
        public string LastName
        {
            get { return this.lastName; }
        }
        public int StudentNumber
        {
            get { return this.socialNumber; }
        }
        public string Adress
        {
            get { return this.adress; }
            private set
            {
                this.adress = value;
            }
        }
        public int MobilePhone
        {
            get { return this.mobilePhone; }
            private set
            {
                this.mobilePhone = value;
            }

        }
        public string Email
        {
            get { return this.email; }
            private set
            {
                this.email = value;
            }
        }
        public string Course
        {
            get { return this.course; }
        }
        public Specialty Specialty
        {
            get { return this.specialty; }
        }
        public University University
        {
            get { return this.university; }
        }
        public Faculty Faculty
        {
            get { return this.faculty; }
        }

        public Student(string firstnam, string middnam, string lastnam, int studNum, string adress, int mobPhone,
            string email, string course, Specialty spec, University uni, Faculty fac)
        {
            this.firstName = firstnam;
            this.middleName = middnam;
            this.lastName = lastnam;
            this.socialNumber = studNum;
            this.adress = adress;
            this.mobilePhone = mobPhone;
            this.email = email;
            this.course = course;
            this.specialty = spec;
            this.university = uni;
            this.faculty = fac;
        }

        public void ChangeEmail(string newEmail)
        {
            this.Email = newEmail;
        }
        public void ChangeAdress(string newAdress)
        {
            this.Adress = newAdress;
        }
        public void ChangeMobile(int newMobile)
        {
            this.MobilePhone = newMobile;
        }

        public override bool Equals(object obj)
        {
            Student stud = obj as Student;
            if (stud == null)
            {
                return false;
            }
            if ((Object.Equals(this.FirstName, stud.FirstName)) && (Object.Equals(this.MiddleName, stud.MiddleName))
                && (Object.Equals(this.LastName, stud.LastName)) && (Object.Equals(this.StudentNumber, stud.StudentNumber)))
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        public static bool operator ==(Student studOne, Student studTwo)
        {
            return Student.Equals(studOne, studTwo);
        }

        public static bool operator !=(Student studOne, Student studTwo)
        {
            return !Student.Equals(studOne, studTwo);
        }


        public override int GetHashCode()
        {
            return this.FirstName.GetHashCode() ^ this.LastName.GetHashCode();
        }

        public override string ToString()
        {
            return string.Format("First Name  :{0}\nMiddle Name :{1}\nLast Name   :{2}\nAdress      :{3}" +
                "\nMobile Phone:{4}\nEmail       :{5}\nCourse      :{6}\nSpecialty   :{7}\nUniversity  :{8}\nFaculty     :{9}",
                this.FirstName, this.MiddleName, this.LastName, this.Adress, this.MobilePhone,
                this.Email, this.Course, this.Specialty, this.University, this.Faculty);
        }

        public Student Clone()
        {
            return
                new Student
                (
                this.FirstName,
                this.MiddleName,
                this.LastName,
                this.StudentNumber,
                this.Adress,
                this.MobilePhone,
                this.Email,
                this.Course,
                this.Specialty,
                this.University,
                this.Faculty
                );
        }

        object ICloneable.Clone()
        {
            return this.Clone();
        }

        public int CompareTo(Student stud)
        {
            if (this.FirstName == stud.FirstName)
            {
                if (this.StudentNumber == stud.StudentNumber)
                {
                    return 0;
                }
                else
                {
                    return (this.StudentNumber - stud.StudentNumber);
                }
            }
            else
            {
                return String.Compare(this.FirstName, stud.FirstName);
            }
        }
    }
}
